<!DOCTYPE html>
<!--
  ~ Copyright (C) 2018 guomw.Inc. All rights reserved.
  ~ 项目名称： mysite
  ~ 文件名称： list.html
  ~ Date：18-10-15 下午3:33
  ~ Author: guomw
  -->

<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/head::head('商品列表')">
<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
    <!--search-->
    <form role="form" class="search-panel">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content p-m no-borders">
                        <div class="form-inline">
                            <div class="form-group m-r-sm">
                                <label class="control-label">姓名：</label>
                                <input type="text" class="form-control input-sm mb10" id="keyword" name="keyword"
                                       placeholder="模糊搜索"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class="control-label">条码：</label>
                                <input type="text" class="form-control input-sm mb10" id="barCode" name="barCode"
                                       placeholder="模糊搜索"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class="control-label">状态：</label>
                                <select id="sl_status" style="height: 34px;" tabindex="2">
                                    <option value="-1">请选择状态</option>
                                    <option value="0">已绑定条码</option>
                                    <option value="1">等待送检</option>
                                    <option value="2" >已送检</option>
                                    <option value="3" >检测中</option>
                                    <option value="4">报告已生成</option>
                                </select>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button" class="btn btn-success" onclick="jsHelper.search()">筛选</button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.searchAll()">显示全部
                                </button>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </form>


    <div class="form-inline font-bold text-right" style="margin-bottom: 6px;">
        <a href="/file/uploadfolder" style="">
            <button type="button" class="btn btn-success">批量上传文件</button>
        </a>
    </div>
    <!--search-->
    <!--list-->
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>用户检测列表</h5>
                </div>
                <div class="ibox-content">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>#</th>
                            <th>条码</th>
                            <th>检测项目</th>
                            <th>用户</th>
                            <th>性别</th>
                            <th>年龄</th>
                            <th>区域</th>
                            <th>地址</th>
                            <th>体重</th>
                            <th>身高</th>
                            <th>状态</th>
                            <th>上链</th>
                            <th>时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="table-content">
                        </tbody>
                    </table>
                    <!--分页控件-->
                    <div th:include="/template/pager::pager"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<template id="template_list">
    <tr>
        <td>{index}</td>
        <td>{barCode}</td>
        <td>{projectName}</td>
        <td>{userName}</td>
        <td>{userGender}</td>
        <td>{userAge}</td>
        <td>{userArea}</td>
        <td>{userAddress}</td>
        <td>{userWeight}</td>
        <td>{userStature}</td>
        <td>{status}</td>
        <td>{chained}</td>
        <td>{createTime}</td>
        <td>
            {btnItems}
        </td>
    </tr>
</template>
<script type="text/html" id="menus_btn_template">
    <a type="button" class="btn-a" data-toggle="modal" data-target="{target}" onclick="{clickMethod}">{title}</a>
</script>

<footer th:include="/common/footer::js"/>
<script>
    /*
 * Copyright (C) 2018 guomw.Inc. All rights reserved.
 * 项目名称： report-manage
 * 文件名称： user.js
 * Date：18-11-6 下午3:16
 * Author: guomw
 */


    $(function () {
        jsHelper.init();
    });
    var jsHelper = {
        localData: null,
        templateList: $("#template_list").html(),
        menusbtnTemplate: $("#menus_btn_template").html(),
        params: {
            keyword: "",
            status: -1,
            pageIndex: 1,
            barCode: ""
        },
        init: function () {
            var self = this;
            hotUtil.loading.show();
            hotUtil.ajaxCall("/user/ajax/genetesting", self.params, function (ret) {
                hotUtil.loading.close();
                if (ret.resultCode === 1) {
                    var data = ret.data;
                    self.localData = data.list;
                    var appendHtml = '';
                    $.each(data.list, function (i, item) {
                        var tempHtml = self.templateList;
                        tempHtml = tempHtml.replace(/{index}/gm, i + 1);
                        tempHtml = tempHtml.replace(/{barCode}/gm, item.barCode);
                        tempHtml = tempHtml.replace(/{userName}/gm, item.userName);
                        tempHtml = tempHtml.replace(/{userGender}/gm, item.userGender == "F" ? "女" : '男');
                        tempHtml = tempHtml.replace(/{userAge}/gm, item.userAge);
                        tempHtml = tempHtml.replace(/{userArea}/gm, item.userArea);
                        tempHtml = tempHtml.replace(/{userAddress}/gm, item.userAddress);
                        tempHtml = tempHtml.replace(/{userWeight}/gm, item.userWeight);
                        tempHtml = tempHtml.replace(/{userStature}/gm, item.userStature);
                        tempHtml = tempHtml.replace(/{projectName}/gm, item.projectName);
                        tempHtml = tempHtml.replace(/{createTime}/gm, item.createTime);
                        tempHtml = tempHtml.replace(/{chained}/gm, item.chained == 1 ? '是' : '否');

                        if (item.status == 0) {
                            tempHtml = tempHtml.replace(/{status}/gm, "已绑定条码");
                        }
                        if (item.status == 1) {
                            tempHtml = tempHtml.replace(/{status}/gm, "等待送检");
                        }
                        if (item.status == 2) {
                            tempHtml = tempHtml.replace(/{status}/gm, "已送检");
                        }
                        if (item.status == 3) {
                            tempHtml = tempHtml.replace(/{status}/gm, "检测中");
                        }
                        if (item.status == 4) {
                            tempHtml = tempHtml.replace(/{status}/gm, "报告已生成");
                        }

                        var btnTempHtml = '';
                        if (item.status == 4) {
                            btnTempHtml += '<a href="/user/reportList/' + item.barCode + '">查看报告</a> ';
                        }
                        else {
                            btnTempHtml += '<a href="/user/uploadReport/' + item.barCode + '">生成报告</a> ';
                        }

                        if (item.chained != 1) {
                            btnTempHtml += '<a href="/user/uploadChain/' + item.barCode + '">上链</a>';
                        }
                        tempHtml = tempHtml.replace(/{btnItems}/, btnTempHtml);

                        appendHtml += tempHtml;
                    });
                    $("#table-content").html(appendHtml);

                    var pageinate = new hotUtil.paging(".pagination", jsHelper.params.pageIndex, 10, data.pageCount, data.totalCount, 7);
                    pageinate.init(function (p) {
                        goTo(p, function (page) {
                            jsHelper.params.pageIndex = page;
                            jsHelper.init();
                        });
                    });
                }
            });
        },
        getModel: function (dataId) {
            var model = null;
            if (this.localData != null && this.localData.length > 0) {
                $.each(this.localData, function (i, item) {
                    if (item.barCode === dataId) {
                        model = item;
                        return false;
                    }
                });
            }
            return model;
        },
        edit: function (dataId) {
            //hotUtil.newTab("user/edit?goodsId=" + dataId, "查看报告[" + dataId + "]");
        },
        search: function () {
            this.params.pageIndex = 1;
            this.params.keyword = $("#keyword").val();
            this.params.status = $("#sl_status").val();
            this.params.barCode = $("#barCode").val();
            this.init();
        },
        searchAll: function () {
            $("#keyword").val("");
            $("#sl_status").val(-1);
            this.params.pageIndex = 1;
            this.params.keyword = "";
            this.params.status = -1;
            this.params.barCode = "";
            this.init();
        }
    }

</script>
</body>
</html>
